import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {HttpClient} from '@angular/common/http';
import {MyData} from './MyData';

@Injectable()
export class DataService {
  constructor(private http: HttpClient) {
  }

  private url: string = 'http://localhost:3060/api/books/';
  private headers = new Headers({'Content-Type': 'application/json'});

  public getData(book_ID: number): Observable<MyData> {
    return this.http.get<MyData>(this.url + book_ID);
  }

  public getAllData(category=''): Observable<MyData> {
    return this.http.get<MyData>(`${this.url}?category=${category}`);
  }

  public postData(rec: MyData): Observable<MyData> {
    return this.http.post<MyData>(this.url, rec);
  }
  public putData(rec: MyData): Observable<MyData> {
    return this.http.put<MyData>(this.url, rec);
  }

  public deleteData(book_ID:any){
    return this.http.delete(this.url+book_ID);
  }
  public getCategorys(): Observable<any> {
    return this.http.get(this.url+'category');
  }

}
